package com.xy.wsl.api.response;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

@Slf4j
@Data
public class Result  implements Serializable {
    private Integer code;
    private String msg;
    private Object data;

    public Result() {

    }
    public Result(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public void setResultCode(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }
    public void setResultCode(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;

    }

    public static Result success() {
        Result result = new Result();
        result.setResultCode(ResultCode.SUCCESS);
        return  result;
    }
    public static Result success(Object data) {
        Result result = new Result();
        result.setResultCode(ResultCode.SUCCESS,data);

        return  result;
    }
    public static Result noauth(String msg) {
        Result result = new Result();
        result.setResultCode(ResultCode.NOAUTH,msg);

        return  result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setResultCode(ResultCode.ERROR);
        result.setMsg(msg);
        return  result;
    }
}
